#include "GameObject.h"

LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
LPDIRECT3DINDEXBUFFER9 i_buffer = NULL;
GameObject::GameObject()
{
	m_pMesh = NULL;
	m_bModel=false;
	m_bTextured=false;
	D3DXVECTOR3 I(0,0,0);
	m_vPos = I;
	m_vAcc = I;
	m_vVel = I;
	m_vRot = I;
	m_vOldPos = I;
	m_NumSubsets=0;
	m_vScale = D3DXVECTOR3(1,1,1);
	m_bDraw=true;
}
GameObject::GameObject(const std::string& type, bool textured, bool model)
{
//	m_pModel = new Model;
	m_bTextured = textured;
	m_bModel = model;

	
	D3DXVECTOR3 I(0,0,0);
	m_vPos = I;
	m_vAcc = I;
	m_vVel = I;
	m_vRot = I;
	m_vOldPos = I;
	m_NumSubsets=0;
	m_vScale = D3DXVECTOR3(1,1,1);
	m_bDraw=true;
	
}
GameObject::GameObject(LPD3DXMESH mesh)
{
	m_pMesh = mesh;
	m_bModel=false;
	m_bTextured=false;
	D3DXVECTOR3 I(0,0,0);
	m_vPos = I;
	m_vAcc = I;
	m_vVel = I;
	m_vRot = I;
	m_vOldPos = I;
	m_NumSubsets=0;
	m_vScale = D3DXVECTOR3(1,1,1);
	m_bDraw=true;
}
GameObject::~GameObject()
{

}
bool GameObject::Load(LPCWSTR filename)
{

	//if(FAILED(m_pModel->Load(filename)))
	{
		return false;
	}
	return true;

}

void GameObject::Transform()
{

}
void GameObject::Render()
{
	if(m_bDraw)
	{

	if(m_bModel)
	{
		//m_pModel->Draw();
	}
	else
	{
		if(m_bTextured)
		{
			m_pTexture->UseThisTexture();
		}
		else
		{
			TheD3DApp::Instance()->GetD3DDev()->SetTexture(0,NULL);
		}
		if(m_pMesh)
		{
			for (UINT i=0;i<=m_NumSubsets;++i)
			{
				m_pMesh->DrawSubset(i);
			}
		
		}
		
	}
	}
}
void GameObject::Update(float dt)
{

	m_vOldPos = m_vPos;

	m_vVel += m_vAcc*dt;
	D3DXVECTOR3 u = m_vVel;
	m_vPos += (m_vVel + u) * (dt * 0.5f);
/*	if(m_pModel!=NULL)
	{
		m_pModel->Update();
	}
*/

}
void GameObject::SetModel(LPCWSTR filename)
{
//	m_pModel = new Model;
//	m_pModel->Load(filename);
	m_bModel = true;
	m_bTextured=true;
}
/*Model* GameObject::GetModel()
{
	return m_pModel;
}*/
void GameObject::Clean()
{
	//m_pTexture->Clean();
	//Need to delete model
	if(m_bModel)
	{
	//delete m_pModel;
	//m_pModel = NULL;
	}
}

void GameObject::SetTexture(LPCWSTR s)
{
	m_bTextured=true;
	m_pTexture=new Texture;
	m_pTexture->LoadTexture(s);
	
}

std::string& GameObject::GetType()
{
	return m_Type;
}

D3DXMATRIX GameObject::GetTransform()
{
	return m_matTranslate;
}

D3DXVECTOR3 GameObject::GetPos()
{
	return m_vPos;
}
float GameObject::GetPosX()
{
	return m_vPos.x;
}
float GameObject::GetPosY()
{
	return m_vPos.y;
}
float GameObject::GetPosZ()
{
	return m_vPos.z;
}

D3DXVECTOR3 GameObject::GetVel()
{
	return m_vVel;
}
float GameObject::GetVelX()
{
	return m_vVel.x;
}
float GameObject::GetVelY()
{
	return m_vVel.y;
}
float GameObject::GetVelZ()
{
	return m_vVel.z;
}

D3DXVECTOR3 GameObject::GetAcc()
{
	return m_vAcc;
}
float GameObject::GetAccX()
{
	return m_vAcc.x;
}
float GameObject::GetAccY()
{
	return m_vAcc.y;
}
float GameObject::GetAccZ()
{
	return m_vAcc.z;
}

D3DXVECTOR3 GameObject::GetScale()
{
	return m_vScale;
}
float GameObject::GetScaleX()
{
	return m_vScale.x;
}
float GameObject::GetScaleY()
{
	return m_vScale.y;
}
float GameObject::GetScaleZ()
{
	return m_vScale.z;
}

D3DXVECTOR3 GameObject::GetRot()
{
	return m_vRot;
}
float GameObject::GetRotX()
{
	return m_vRot.x;
}
float GameObject::GetRotY()
{
	return m_vRot.y;
}
float GameObject::GetRotZ()
{
	return m_vRot.z;
}

D3DXVECTOR3 GameObject::GetOldPos()
{
	return m_vOldPos;
}

//Set
void  GameObject::SetPos(D3DXVECTOR3 v)
{
	m_vPos=v;
}
void  GameObject::SetPosX(float f)
{
	m_vPos.x = f;
}
void  GameObject::SetPosY(float f)
{
	m_vPos.y = f;
}
void  GameObject::SetPosZ(float f)
{
	m_vPos.z = f;
}


void  GameObject::SetVel(D3DXVECTOR3 v)
{
	m_vVel=v;
}
void  GameObject::SetVelX(float f)
{
	m_vVel.x = f;
}
void  GameObject::SetVelY(float f)
{
	m_vVel.y = f;
}
void  GameObject::SetVelZ(float f)
{
	m_vVel.z = f;
}


void  GameObject::SetAcc(D3DXVECTOR3 v)
{
	m_vAcc=v;
}
void  GameObject::SetAccX(float f)
{
	m_vAcc.x = f;
}
void  GameObject::SetAccY(float f)
{
	m_vAcc.y = f;
}
void  GameObject::SetAccZ(float f)
{
	m_vAcc.z = f;
}


void  GameObject::SetScale(D3DXVECTOR3 v)
{
	m_vScale=v;
}
void  GameObject::SetScaleX(float f)
{
	m_vScale.x = f;
}
void  GameObject::SetScaleY(float f)
{
	m_vScale.y = f;
}
void  GameObject::SetScaleZ(float f)
{
	m_vScale.z = f;
}

void  GameObject::SetRot(D3DXVECTOR3 v)
{
	m_vRot=v;
}
void  GameObject::SetRotX(float f)
{
	m_vRot.x = f;
}
void  GameObject::SetRotY(float f)
{
	m_vRot.y = f;
}
void  GameObject::SetRotZ(float f)
{
	m_vRot.z = f;
}



void  GameObject::SetOldPos(D3DXVECTOR3 v)
{
	m_vOldPos = v;
}